package com.huyanqi.core.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
 * 
 * <p>Title: JaxbCalendarSerializer.java</p>
 * 
 * <p>Description: 用来进行实体类Calendar属性注解</p>
 * 
 * <p>Datetime: 2012-1-4 上午11:48:36</p>
 *
 * @company 成都映潮科技有限公司
 * 
 * @author <a href="mailto:liwei@sunsharp.cn">p.k.ripper</a>
 *
 */
public class JaxbCalendarSerializer extends XmlAdapter<String, Calendar>{

    private SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_TIME_PATTERN);
    
    @Override
    public String marshal(Calendar date) throws Exception {
    	if(null==date)return null;
        return dateFormat.format(date.getTime());
    }

    @Override
    public Calendar unmarshal(String date) throws Exception {
    	if(null==date||"".equals(date))return null;
    	Calendar calendar =Calendar.getInstance();
    	calendar.setTime(dateFormat.parse(date));
    	return calendar;
    }


}
